package weaver.interfaces.xfjt.action;

import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.hrm.resource.ResourceComInfo;
import weaver.interfaces.workflow.action.Action;
import weaver.interfaces.xfjt.utils.XfjtUtil;
import weaver.jobs.xfjt.duss.utils.WorkflowCreateHandler;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-10-07
 * @Description: 单次任务反馈流程归档更新任务台账状态和信息
 * @ModifyLog:
 **/
public class WeaFeedbackTaskAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        writeLog(">>>>WeaFeedbackTaskAction" + requestid);
        RecordSet rs = new RecordSet();
        try {
            rs.executeQuery("select * from " + tablename + " where requestid=?", requestid);
            rs.next();
            //建模数据ID
            String jmid = Util.null2String(rs.getString("jmid"));
            String fkrq = Util.null2String(rs.getString("fkrq"));
            String fknr = Util.null2String(rs.getString("fknr"));
            String fkfj = Util.null2String(rs.getString("fkfj"));
            String wcrq = DateUtil.getCurrentDate();
            String sql = "update uf_dcrwtz_dt1 set fkrq=?,fknr=?,fkfj=?,wcrq=?,sfyfk=0 " +
                    " where mainid=? and fklc=?";
            Object[] params = new Object[] {fkrq, fknr, fkfj, wcrq, jmid, requestid};
            rs.executeUpdate(sql, params);
            writeLog(">>>>WeaFeedbackTaskAction>>>sql=" + sql);
            writeLog(">>>>WeaFeedbackTaskAction>>>params=" + params.toString());
            rs.executeQuery("select count(id) from uf_dcrwtz_dt1 where mainid=? and sfyfk=1", jmid);
            rs.next();
            int count = Util.getIntValue(rs.getString(1));
            writeLog(">>>>WeaFeedbackTaskAction>>>count=" + count);
            if(count==0){
                rs.executeUpdate("update uf_dcrwtz set sjwcrq=?,rwzt=1 where id=?",wcrq,jmid);
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口异常！");
            return Action.FAILURE_AND_CONTINUE;
        }
    }

}
